package com.xia.demo1;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileReader {


    public static void  myReadFile(String pathName) {
        File file = new File(pathName);
            if (file.isDirectory()) {
                // 继续读
                String[] list = file.list();
                for (int i = 0; i < list.length; i++) {
                    File file1 = new File(pathName + "\\" + list[i]);
                    if (!file1.isDirectory()) {
                        System.out.println(file1.getAbsolutePath());
                    } else {
                        myReadFile(pathName + "\\" + list[i]);
                    }
                }
            } else {
                System.out.println(file.getAbsolutePath());
            }
    }

    static int iFile = 0;

    public static void clear( File dir )
    {
        File[] dirs = dir.listFiles();
        for( int i = 0; i < dirs.length; i++ )
        {
            if( dirs[i].isDirectory() )
            {
                clear( dirs[i] );
            }
        }
        if( dir.isDirectory() && dir.delete() ) {
            iFile++;
        }
        System.out.println( dir + "清理成功" );

    }


    public static void main(String[] args) throws IOException {
//        myReadFile("d://downloadtest");
        File file = new File("d://downloadtest");
        clear(file);
//        readfile("d://downloadtest");

    }


}
